<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>门店区域划分表管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			var tpl = $("#treeTableTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			var data = ${fns:toJson(list)}, ids = [], rootIds = [];
			for (var i=0; i<data.length; i++){
				ids.push(data[i].id);
			}
			ids = ',' + ids.join(',') + ',';
			for (var i=0; i<data.length; i++){
				if (ids.indexOf(','+data[i].parentId+',') == -1){
					if ((','+rootIds.join(',')+',').indexOf(','+data[i].parentId+',') == -1){
						rootIds.push(data[i].parentId);
					}
				}
			}
			for (var i=0; i<rootIds.length; i++){
				addRow("#treeTableList", tpl, data, rootIds[i], true);
			}
			$("#treeTable").treeTable({expandLevel : 5});
		});
		function addRow(list, tpl, data, pid, root){
			for (var i=0; i<data.length; i++){
				var row = data[i];
				if ((${fns:jsGetVal('row.parentId')}) == pid){
					$(list).append(Mustache.render(tpl, {
						dict: {
							investigationPersonId: getDictLabel(${fns:toJson(fns:getDictList(''))}, row.investigationPersonId),
						blank123:0}, pid: (root?0:pid), row: row
					}));
					addRow(list, tpl, data, row.id);
				}
			}
		}
		
			/* -------------------------- */
		$(document).ready(function() {
				$("#btnExport").click(function(){
					top.$.jBox.confirm("确认要导出用户数据吗？","系统提示",function(v,h,f){
						if(v=="ok"){
							$("#searchForm").attr("action","${ctx}/ajz/ajzBaseinfo/export");
							$("#searchForm").submit();
						}
					},{buttonsFocus:1});
					top.$('.jbox-body .jbox-icon').css('top','55px');
				});
				$("#btnImport").click(function(){
					$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true}, 
						bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
				});
			});
	</script>
</head>
<body>
   <div id="importBox" class="hide">
		<form id="importForm" action="${ctx}/ajz/ajzBaseinfo/import" method="post" enctype="multipart/form-data"
			class="form-search" style="padding-left:20px;text-align:center;" onsubmit="loading('正在导入，请稍等...');"><br/>
			<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
			<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
			<br/><br/>
			<a style="float:left;margin-left:3%" href="${ctx}/ajz/ajzBaseinfo/import/anquanTemplate">下载安全生产模板</a>
			&nbsp;
			<a href="${ctx}/ajz/ajzBaseinfo/import/shipinTemplate">下载食品模板</a>
			<br>
			<a style="float:left;margin-left:3%" href="${ctx}/ajz/ajzBaseinfo/import/xfczwTemplate">下载消防出租屋基础模板</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="${ctx}/ajz/ajzBaseinfo/import/xfdmTemplate">下载消防店面基础模板</a>
			<br>
			<a style="float:left;margin-left:3%" href="${ctx}/ajz/ajzBaseinfo/import/rqgdTemplate">下载管道燃气安全检查模板</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="${ctx}/ajz/ajzBaseinfo/import/rqghTemplate">下载液化石油安全检查模板</a>
			<br/>
		</form>
	</div>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ajz/ajzBaseinfo/">门店区域划分表列表</a></li>
		<shiro:hasPermission name="ajz:ajzBaseinfo:edit"><li><a href="${ctx}/ajz/ajzBaseinfo/form">门店区域划分表添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="ajzBaseinfo" action="${ctx}/ajz/ajzBaseinfo/" method="post" class="breadcrumb form-search">
		<ul class="ul-form">
			<li><label>单位名称：</label>
				<form:input path="enterpriseName" htmlEscape="false" maxlength="100" class="input-medium"/>
			</li>
			<li><label>负责人姓名：</label>
				<form:input path="chargePerson" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li><label>经营者姓名：</label>
				<form:input path="managerPerson" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li><label>排查人员：</label>
				<form:select path="investigationPersonId" class="input-medium">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li class="btns" style="float:right;margin-right:7%">
				<!-- <input id="btnExport" class="btn btn-primary" type="button" value="导出"/> -->
				<shiro:lacksPermission name="sys:user:edit">
					<input id="btnImport" class="btn btn-primary" type="button" value="导入"/>
				</shiro:lacksPermission>
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" />
			</li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="treeTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>单位名称</th>
				<th>负责人姓名</th>
				<th>经营者姓名</th>
				<th>电话</th>
				<th>门店信息</th>
				<th>更新时间</th>
				<shiro:hasPermission name="ajz:ajzBaseinfo:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody id="treeTableList"></tbody>
	</table>
	<script type="text/template" id="treeTableTpl">
		<tr id="{{row.id}}" pId="{{pid}}">
			<td><a href="${ctx}/ajz/ajzBaseinfo/form?id={{row.id}}">
				{{row.enterpriseName}}
			</a></td>
			<td>
				{{row.chargePerson}}
			</td>
			<td>
				{{row.managerPerson}}
			</td>
			<td>
				{{row.telephone}}
			</td>
			<td>
				{{row.storeInfo}}
			</td>
			<td>
				{{row.updateDate}}
			</td>
			<shiro:hasPermission name="ajz:ajzBaseinfo:edit"><td>
   				<a href="${ctx}/ajz/ajzBaseinfo/form?id={{row.id}}">修改</a>
				<a href="${ctx}/ajz/ajzBaseinfo/delete?id={{row.id}}" onclick="return confirmx('确认要删除该门店区域划分表及所有子门店区域划分表吗？', this.href)">删除</a>
				</td></shiro:hasPermission>
		</tr>
	</script>
</body>
</html>